package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    //添加购物车
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
    void addShoppingCart(ShoppingCart shoppingCart);

    //判断购物车是否是第一次添加
    List<ShoppingCart> ifExistShoppingCart(ShoppingCart shoppingCart);

    //将购物车表的数量字段加一
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNumber(ShoppingCart cart);

    //查看购物车
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> checkShoppingCart(ShoppingCart shoppingCart);

    //清空购物车
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void cleanShoppingCart(ShoppingCart shoppingCart);

    //删除购物车中的一个商品
    void deleteByOneShoppingCart(ShoppingCart shoppingCart);
}
